﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <script>
        // includes()  返回数组中是否包含参数这个元素 
        var arr = ["a", "b", "c"];
        var n = arr.includes("a");
        console.log(n); // true/false

        // 
        var str = "b";
        if (str === arr[0] || str === arr[1] || str === arr[2]) {
            console.log(true);
        } else {
            console.log(false);
        }

        // 
        var isshow = false;
        for (var i = 0; i < arr.length; i++) {
            if (str === arr[i]) {
                isshow = true
            }
        }
        console.log(isshow);


        // 
        function includes2(array, string) {
            for (var i = 0; i < array.length; i++) {
                if (string === array[i]) {
                    return true
                }
            }
            return false;
        }

        console.log(includes2(arr, str));

        // 
        Array.prototype.includes3 = function (string) {
            for (var i = 0; i < this.length; i++) {
                if (string === this[i]) {
                    return true
                }
            }
            return false;
        }
        console.log(arr.includes3("b"));
    </script>
</body>
</html>